package com.mkk.pro.base.activity

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.mkk.pro.MyApp
import com.mkk.pro.base.mvp.IBaseView
import org.jetbrains.anko.toast

abstract class BaseActivity:AppCompatActivity() ,IBaseView{

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        MyApp.helper!!.onActivityCreated(this, savedInstanceState)
        if(getLayoutId()!=0){
            setContentView(getLayoutId())
            initViews()
        }else{
            throw RuntimeException("A valid layoutId must be provided")
        }
    }

    override fun onStart() {
        super.onStart()
    }

    override fun onResume() {
        super.onResume()
    }

    override fun onPause() {
        super.onPause()
    }

    override fun onStop() {
        super.onStop()
    }

    override fun onDestroy() {
        super.onDestroy()
        MyApp.helper!!.onActivityDestroyed(this)
    }

    protected abstract fun getLayoutId(): Int

    protected abstract fun initViews()

    override fun showToast(msg: String) {
          toast(msg)
    }

    override fun showLoadingDialog(msg: String, cancelable: Boolean) {

    }

    override fun showErrorDialog(msg: String) {

    }

    override fun hideDialog() {

    }

}